package com.seh.contentcenter.utils;

import com.alibaba.fastjson.JSONObject;
import com.seh.contentcenter.dto.UserDTO;
import com.seh.contentcenter.feignclient.UserCenterFeignClient;
import org.springframework.data.redis.core.RedisTemplate;

public class UserUtil {

    public static UserDTO getUserDTOFromCache(Integer userId, RedisTemplate<String, Object> objectRedisTemplate, UserCenterFeignClient userCenterFeignClient) {
        Boolean hasKey = objectRedisTemplate.opsForHash().hasKey("users", userId.toString());
        UserDTO userDTO;
        if (hasKey) {
            userDTO = JSONObject.parseObject(objectRedisTemplate.opsForHash().get("users", userId.toString()).toString(), UserDTO.class);
        } else {
            userDTO = userCenterFeignClient.findUserInfoById(userId);
        }
        return userDTO;
    }


}
